export default function (Vue, options) {
    /*
    * 将数据库传入的整型金额转换为以分为单位的金额
    */
    Vue.prototype.AmountCalculation = function(value, len) {
        return (value / 100).toFixed(len);
    };

    /**
     * 将对象转为查询参数
     */
    Vue.prototype.FormattingQueryStr = function(param) {
        let query = "";
        for (let key in param){
            let item = param[key];
            switch (typeof(item)) {
                case 'number':
                    query += `&${key}=${item}`
                    break;
                case 'boolean':
                    query += `&${key}=${JSON.stringify(item)}`
                    break;
                case 'string':
                    if(item)query += `&${key}=${encodeURIComponent(item.replace(/\s+/g, ""))}`;
                    break;
                case 'object':
                    if(Array.isArray(item) && item.length > 0) query += `&${key}=${item.join(",")}`;
                    break;
                default:
                    if(item)query += `&${key}=${JSON.stringify(item)}`;
                    break;
            }
        }
        return (this.startsWith(query, '&'))?`?${query.substr(1)}`:(query)?`?${query}`:``;
    };

    /**
     * 判断字符串是否以char开头
    */
    Vue.prototype.startsWith = function(FullString,character) {
        return (FullString.indexOf(character)) >= 0 ? true: false; 
    };

    /**
     *  富文本图片宽度自适应
     */
    Vue.prototype.formatRichText = function(html) {
        const newContent = html.replace(/style=\"\"/gi,'');
        return newContent.replace(/\<img/gi, '<img style="max-width:100%;height:auto;display:block;"');
    };
}